package com.ruoyi.project.base.postInfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.base.postInfo.domain.PostInfo;
import com.ruoyi.project.base.postInfo.service.IPostInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 岗位信息Controller
 * 
 * @author ruoyi
 * @date 2021-01-23
 */
@Controller
@RequestMapping("/base/postInfo")
public class PostInfoController extends BaseController
{
    private String prefix = "base/postInfo";

    @Autowired
    private IPostInfoService postInfoService;

    @RequiresPermissions("base:postInfo:view")
    @GetMapping()
    public String postInfo()
    {
        return prefix + "/postInfo";
    }

    /**
     * 查询岗位信息列表
     */
    @RequiresPermissions("base:postInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PostInfo postInfo)
    {
        startPage();
        List<PostInfo> list = postInfoService.selectPostInfoList(postInfo);
        return getDataTable(list);
    }

    /**
     * 导出岗位信息列表
     */
    @RequiresPermissions("base:postInfo:export")
    @Log(title = "岗位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PostInfo postInfo)
    {
        List<PostInfo> list = postInfoService.selectPostInfoList(postInfo);
        ExcelUtil<PostInfo> util = new ExcelUtil<PostInfo>(PostInfo.class);
        return util.exportExcel(list, "postInfo");
    }

    /**
     * 新增岗位信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存岗位信息
     */
    @RequiresPermissions("base:postInfo:add")
    @Log(title = "岗位信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PostInfo postInfo)
    {
        return toAjax(postInfoService.insertPostInfo(postInfo));
    }

    /**
     * 修改岗位信息
     */
    @GetMapping("/edit/{postId}")
    public String edit(@PathVariable("postId") Long postId, ModelMap mmap)
    {
        PostInfo postInfo = postInfoService.selectPostInfoById(postId);
        mmap.put("postInfo", postInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存岗位信息
     */
    @RequiresPermissions("base:postInfo:edit")
    @Log(title = "岗位信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PostInfo postInfo)
    {
        return toAjax(postInfoService.updatePostInfo(postInfo));
    }

    /**
     * 删除岗位信息
     */
    @RequiresPermissions("base:postInfo:remove")
    @Log(title = "岗位信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(postInfoService.deletePostInfoByIds(ids));
    }


    @PostMapping( "/queryPostList")
    @ResponseBody
    public List<PostInfo> queryPostList(PostInfo postInfo){
        List<PostInfo> postInfos = postInfoService.selectPostInfoList(postInfo);
        return  postInfos;
    }
}
